<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <h1>login</h1>
 用户名 <input type="text" id="username"></br>
  密码 <input type="password" id="password"><br/>
  <button id="login">登录</button>

  <script>
    const username = document.querySelector('#username')
    const password = document.querySelector('#password')
    const login = document.querySelector('#login')

    login.onclick = () => {
      fetch('/login',{
        method:'POST',
        body: JSON.stringify({username:username.value,password:password.value}),
        headers: {
          "Content-Type":"application/json"
        }
      }).then(res => res.json())
      .then(res => {
        console.log(res)
        if(res.ok == 1) {
          location.href = '/all'
        }
      })
    }
  </script>
</body>
</html>